
'use strict';
import React from 'react';
import ReactDOM from 'react-dom';
import echarts from 'echarts';
import Order        from 'service/order.jsx';
const _order        = new Order();
const Chart = React.createClass({

    componentDidMount: function () {

        this.showChart()

    },

    showChart: function (dataSet) {

        const myChart = echarts.init(document.getElementById('main'));
        const optionLeft = {
            title: {
                text: '销量统计'
            },
            tooltip: {},
            legend: {
                data: ['销量']
            },
            xAxis: {
                data: []
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'bar',
                data: []
            }]
        };
        _order.getOrderCategorySum().then(res => {
            res = res || [];
            var leftx = [];
            var lefty = [];
            res.forEach(function (value, i) {
                leftx.push(value.name);
                lefty.push(value.quantity) 
            });
            //月份数组
            optionLeft.xAxis.data = leftx;
            //销量数组
            optionLeft.series[0].data = lefty;
            myChart.setOption(optionLeft);
        }, errMsg => {
            myChart.setOption(optionLeft);
            alert(errMsg);
        });
    },



    render: function () {

        return (

            <p id="main" style={{ width: 500, height: 500 }}></p>

        )

    }

});
export default Chart;